<template>
	<view class="content">
		<view class="from-info-box">
			<view class="from-item-box">
				<view class="title-box">
					<text>试打产品</text>
				</view>
				<view class="input-box">
					<input type="text" v-model="fromInfo.trial_product" placeholder="请填写试打产品" placeholder-style="color:#CCC">
				</view>
			</view>
			<view class="from-item-box">
				<view class="title-box">
					飞行距离<text class="dw">[单位：yards]</text>
				</view>
				<view class="input-box">
					<input type="text" v-model="fromInfo.trial_distance" placeholder="请填写飞行距离" placeholder-style="color:#CCC">
				</view>
			</view>
			<view class="from-item-box">
				<view class="title-box">
					倒旋<text class="dw">[单位：rpm]</text>
				</view>
				<view class="input-box">
					<input type="text" v-model="fromInfo.trial_rotation" placeholder="请填写倒旋" placeholder-style="color:#CCC">
				</view>
			</view>
			<view class="from-item-box">
				<view class="title-box">
					<text>smash</text>
				</view>
				<view class="input-box">
					<input type="text" v-model="fromInfo.trial_smash" placeholder="请填写smash" placeholder-style="color:#CCC">
				</view>
			</view>
			<view class="from-item-box">
				<view class="title-box">
					<text>购买产品</text>
				</view>
				<view class="input-box">
					<input type="text" v-model="fromInfo.trial_buy_product" placeholder="请填写最终购买的产品" placeholder-style="color:#CCC">
				</view>
			</view>
			<view class="from-item-box">
				<view class="title-box">
					<text>上传图片</text>
				</view>
				<view class="input-box">
					<view class="upload-img-box flex-c-w">
						<view class="upload-img-box-item" v-for="(item,index) in imgUrls" @click="bindImgPreview(index)" :key="item.id">
						    <image :src="item.path" mode="aspectFill"></image>
							<view class="del" @click.stop="bindDel(index)">
								<image src="/pageIndex/static/icon24.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="upload-img-item" @click="bindAddImg">
						    <image src="/pageIndex/static/icon22.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-plate-box">
			<!-- 底部but -->
			<view class="bottom-but-box" @click="bindSubmit(2)">
				<text>提交数据</text>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data(){
			return {
				imgUrls:[],//图片集合
				fromInfo:{ //表单信息
					activity_id:0,
					trial_product:"",
					trial_distance:"",
					trial_rotation:"",
					trial_smash:"",
					trial_buy_product:"",
					trial_picture:""
				}
			}
		},
		onLoad(options) {
			this.fromInfo.activity_id = options.activityId; //获取活动ID
		},
		methods:{
			bindImgPreview(index){//图片预览
				let target = {};
				target.cur = index;
				target.urls = this.imgUrls.map(res => res.path);
				this.$lookImage(target);
			},
			bindAddImg(){//图片上传
				this.$uploadPic(9, res => {
					this.imgUrls = this.imgUrls.concat(res);
				});
			},
			bindSubmit(id){ //表单提交
				let {trial_product,trial_distance,trial_rotation,trial_smash,trial_buy_product} = this.fromInfo;
				if(trial_product==""){
					this.$showToast("请填写试打产品");
					return
				}
				if(trial_distance==""){
					this.$showToast("请填写飞行距离");
					return
				}
				if(trial_rotation==""){
					this.$showToast("请填写倒旋");
					return
				}
				if(trial_smash==""){
					this.$showToast("请填写smash");
					return
				}
				// if(trial_buy_product==""){
				// 	this.$showToast("请填写最终购买的产品");
				// 	return
				// }
				// if(this.imgUrls.length==0){
				// 	this.$showToast("请上传图片");
				// 	return
				// }
				let imgArrs = this.imgUrls.map(res => res.id);
				this.fromInfo.trial_picture = imgArrs.toString();
				uni.showLoading({title:'提交中...'});
				console.log('提交的数据：',this.fromInfo);
				this.$u.api.activityDataApi(this.fromInfo).then(res=>{
					if(res.code==1){
						setTimeout(()=>{
							this.$gourl(`./success?status=${id}`);
						},1500);
					}
				});
			},
			bindDel(index){ //删除图片
				this.imgUrls.splice(index,1);
				this.$refs.uToast.show({title: '删除成功',position:'center'});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: calc(100vh - 120rpx);
		overflow: hidden;overflow-y: auto;
		font-family: Microsoft YaHei;
		box-sizing: border-box;
		.from-info-box{
			padding: 30rpx;
			.from-item-box{
				padding: 20rpx 0;
				.title-box{
					font-size: 34rpx;
					font-weight: bold;
					color: #333333;
					margin-bottom: 20rpx;
					.dw{
						font-size: 26rpx;
						color: #999999;
						margin-left: 10rpx;
					}
				}
				.input-box{
					position: relative;
					width: 100%;
					input{
						font-size: 30rpx;
						font-weight: 400;
						padding: 30rpx;
						border: 1rpx solid #000;
						border-radius: 20rpx;
					}
					.upload-img-box{
						width: 100%;
						.upload-img-box-item{
							position: relative;
							line-height: 0;
							image{width: 210rpx;height: 210rpx;margin: 0 20rpx 20rpx 0;border-radius: 14rpx;}
							.del{
								position: absolute;
								top: 0;
								right: 20rpx;
								image{width: 50rpx; height: 50rpx;margin: auto;border-radius: 0 14rpx 0 0;}
							}
						}
						.upload-img-item{
							width: 210rpx;
							height: 210rpx;
							background: rgba(0, 0, 0, 0);
							border: 1rpx solid #000000;
							border-radius: 14rpx;
							margin-bottom: 20rpx;
							display: flex; justify-content: center; align-items: center;
							image{width: 60rpx;height: 60rpx;}
						}
					}
				}
				
			}
		}
		.bottom-plate-box{
			position: fixed;bottom: 0;
			z-index: 100;
			width: 100%;
			padding:20rpx;
			background: #fff;
		.bottom-but-box{
			width: 100%;
			padding: 25rpx 0;
			background: #000;
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			border-radius: 50rpx;
			}
		}
	}
</style>